{{--@extends ('shop-backend::layout')--}}

{{--@section ('title',  '门店活动 | 添加活动')--}}

{{--@section ('breadcrumbs')--}}
    {{--<h2>添加活动</h2>--}}
    {{--<ol class="breadcrumb">--}}
        {{--<li><i class="fa fa-dashboard"></i> 首页</li>--}}
        {{--<li>{!! link_to_route('admin.shop.list.activity', '活动') !!}</li>--}}
        {{--<li class="active">添加活动</li>--}}
    {{--</ol>--}}
{{--@stop--}}
{{--@section('after-styles-end')--}}
    {!! Html::style(env("APP_URL").'/assets/backend/libs/datepicker/bootstrap-datetimepicker.min.css') !!}
    {!! Html::style(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.css') !!}
    {!! Html::style(env("APP_URL").'/assets/backend/libs/loader/jquery.loader.min.css') !!}
{{--@stop--}}
{{--@section('content')--}}
    <div class="ibox float-e-margins">
        <div class="ibox-content" style="display: block;">
            {!! Form::open(['route' => 'admin.shop.list.activity.save', 'id' => 'create-activity-form', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'post', 'files' => true]) !!}

            <div class="form-group">
                <label for="store-act-name" class="col-md-2 control-label">
                    <span style="color: red">*</span>活动名：
                </label>
                <div class="col-lg-10">
                    {!! Form::text('store-act-name', isset($activity) && !empty($activity->name) ? $activity->name : null, ['class' => 'form-control', 'placeholder' => '', 'required']) !!}
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('store-act-url', '活动链接', ['class' => 'col-lg-2 control-label']) !!}
                <div class="col-lg-10">
                    {!! Form::text('store-act-url', isset($activity) && !empty($activity->url) ? $activity->url : null, ['class' => 'form-control', 'placeholder' =>'']) !!}
                </div>
            </div>

            <div class="form-group" id="card_cover_img">
                <label class="col-md-2 control-label">活动图片：</label>
                <div class="col-md-7">
                    <div class="pull-left" id="activity-poster">
                        <img src={{isset($activity) && !empty($activity->file_url) ? $activity->file_url : "/assets/backend/activity/backgroundImage/pictureBackground.png"}} alt="" class="img" width="226px" height="91px" style="margin-right: 23px;">
                        <input type="hidden" class="form-control" id="store-act-img" name="store-act-img" value="{{ isset($activity) && !empty($activity->file_url) ? $activity->file_url : '' }}">
                    </div>
                    <div id="filePicker" class="pull-left clearfix" style="margin-left:30px; padding-top: 22px;">
                        <span data-style="expand-right" class="ladda-button">上传图片</span>
                    </div>
                </div>
                <input type="hidden" class="form-control" id="bg_img_wx" name="bg_img_wx" value="">
            </div>

            <div class="form-group">
                <label for="store-act-time" class="col-md-2 control-label">
                    <span style="color: red">*</span>活动时间：
                </label>
                <div class="col-lg-10" style='display:inline-block'>
                    {!! Form::text('store-act-starttime', isset($activity) && !empty($activity->act_starttime) ? date('Y-m-d', $activity->act_starttime) : null, ['class' => 'form-control date form_datetime', 'placeholder' =>'开始', 'style' => 'width:150px;float:left;', 'data-date-format'=>'yyyy-mm-dd', 'required']) !!}
                    <div style='float:left;'>-</div>
                    {!! Form::text('store-act-endtime', isset($activity) && !empty($activity->act_endtime) ? date('Y-m-d', $activity->act_endtime) : null, ['class' => 'form-control date form_datetime', 'placeholder' =>'截止', 'style' => 'width:150px;float:left;', 'data-date-format'=>'yyyy-mm-dd', 'required']) !!}
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-10">
                    {!! Form::hidden('store-act-id', isset($activity) && !empty($activity->id) ? $activity->id : 0) !!}
                </div>
            </div>

            <div class="well">
                <div class="pull-right">
                    <input type="submit" class="btn btn-success btn-xs" value="保存" />
                </div>
                <div class="clearfix"></div>
            </div>

            {!! Form::close() !!}
        </div>
    </div>
{{--@stop--}}
{{--@section('after-scripts-end')--}}
    {!! Html::script(env("APP_URL").'/assets/backend/admin/js/plugins/jquery-ui/jquery-ui.min.js') !!}
    {!! Html::style(env("APP_URL").'/assets/backend/activity/css/jquery-ui.min.css') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/datepicker/bootstrap-datetimepicker.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/datepicker/bootstrap-datetimepicker.zh-CN.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/webuploader-0.1.5/webuploader.js') !!}
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/spin.min.js') !!}
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/ladda.min.js') !!}
    {!! Html::script(env("APP_URL").'/assets/wechat-backend/libs/ladda/ladda.jquery.min.js') !!}
    <script>
        $(document).ready(function(){
            var postImgUrl = '{{route('upload.image',['_token'=>csrf_token()])}}';
            // 初始化Web Uploader
            var uploader = WebUploader.create({
                auto: true,
                swf: '{{url('assets/backend/libs/webuploader-0.1.5/Uploader.swf')}}',
                server: postImgUrl,
                pick: '#filePicker',
                fileVal: 'upload_image',
                accept: {
                    title: 'Images',
                    extensions: 'jpg,jpeg,png',
                    mimeTypes: 'image/jpg,image/jpeg,image/png'
                }
            });


            // 文件上传成功，给item添加成功class, 用样式标记上传成功。
            uploader.on('uploadSuccess', function (file, response) {
                $('#activity-poster img').attr("src", response.url);
                $('#activity-poster input').val(response.url);
            });
        });

        $(function () {
            $('#create-activity-form').ajaxForm({
                success: function (result) {
                    if (200 == result.code) {
                        swal({
                            title: "保存成功！",
                            text: "",
                            type: "success"
                        }, function () {
                            window.location = '{{route('admin.shop.list.activity')}}';
                        });
                    } else {
                        swal("保存失败!", result.message, "error")
                    }

                }
            });


            $('.form_datetime').datetimepicker({
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                forceParse: 0,
                showMeridian: 1,
                minuteStep: 1
            });
        });
    </script>
{{--@stop--}}